package com.iven.xie.aop.bytecodege;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 记录日志
 */
public class LogIntercept implements MethodInterceptor {
    @Override
    public Object intercept(Object target, Method method, Object[]
            args, MethodProxy proxy) throws Throwable {
        //执行原有逻辑，注意这里是invokeSuper
        Object rev = proxy.invokeSuper(target, args);
        //执行织入的日志
        if (method.getName().equals("doSomeThing2")) {
            System.out.println("记录日志");
        }
        return rev;
    }

}
